package com.atguigu.servlet;

import javax.servlet.*;
import java.io.IOException;

public class ThirdServlet implements Servlet {

    private ServletConfig servletConfig;

    @Override

    public void init(ServletConfig servletConfig) throws ServletException {
        this.servletConfig = servletConfig;
        //获取友好名称
//        String servletName = servletConfig.getServletName();
//        System.out.println("友好名称————》"+servletName);
        String servletName = servletConfig.getServletName();
        System.out.println("友好名称————》"+servletName);
        //获取s
        String initParameter = servletConfig.getInitParameter("namespace");
        System.out.println("servlet的初始化参数__>"+initParameter);

//        String testServletInitParam = servletConfig.getInitParameter("testServletInitParam");
//        System.out.println("servlet的初始化参数__>"+testServletInitParam);
//        //获取对象
        ServletContext servletContext = servletConfig.getServletContext();
//        ServletContext servletContext = servletConfig.getServletContext();
        ////通过ServletContext获取当前工程的编译路径

        String realPath = servletContext.getRealPath("");
        System.out.println("当前工程的编译路径-->"+realPath);


//        String realPath = servletContext.getRealPath("");
//        System.out.println("当前工程的编译路径-->"+realPath);

        //通过ServletContext获取当前工程的初始化参数

        String niihao = servletContext.getInitParameter("niihao");
        System.out.println("当前工程下的————》"+niihao );


//        String testContextParam = servletContext.getInitParameter("testContextParam");
//        System.out.println("当前工程下的————》"+testContextParam);

        //域对象
       servletContext.setAttribute("Socpe","zqk域对象");
//        servletContext.setAttribute("testScope", "ServletContext域对象");

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {

    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
